package dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import to.Assinatura;
import util.HibernateUtil;

public class AssinaturaDAO {

	public Assinatura buscaAssinaturaPorCodigo(Integer idAssinatura) {

		Assinatura a = new Assinatura();
		Session session = null;

		try {

			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Assinatura.class, "a");
			criteria.add(Restrictions.eq("a.id", idAssinatura));
			a = (Assinatura) criteria.uniqueResult();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return a;
	}

	public List<Assinatura> listaAssinatura() {

		List<Assinatura> lista = new ArrayList<Assinatura>();
		Session session = null;

		try {

			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Assinatura.class, "a");
			criteria.addOrder(Order.asc("a.nome"));
			lista = (List<Assinatura>) criteria.list();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return lista;
	}

}
